<template>
  <el-dialog :title="title" top="100px" width="600px" append-to-body :visible.sync="dialogedit" @open="openDialog"
    :before-close="closeDialog" :close-on-click-modal="false">
    <div class="form-box">
      <el-form ref="formdata" :model="ruleform" :rules="rules" label-suffix="：" :validate-on-rule-change="false"
        :show-message="false" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="填写日期" prop="rq">
              <el-date-picker v-model="ruleform.rq" type="month" style="width: 100%;" value-format="yyyy-MM"
                placeholder="选择填写日期">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="产妇人数" prop="cfcs">
              <el-input-number v-model="ruleform.cfcs" placeholder="请输入产妇人数" :controls="false" clearable
                style="width: 100%;"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="早孕建册人数" prop="zycs">
              <el-input-number v-model="ruleform.zycs" placeholder="请输入早孕建册人数" :controls="false" clearable
                style="width: 100%;"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="产后访视人数" prop="fscs">
              <el-input-number v-model="ruleform.fscs" placeholder="请输入产后访视人数" :controls="false" clearable
                style="width: 100%;"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="早孕建册率" prop="zyjcl">
              <el-input-number v-model="ruleform.zyjcl" placeholder="请输入早孕建册率" :controls="false" clearable min="0"
                max="100" precision="2" style="width: 100%;"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="产后访视率" prop="chfsl">
              <el-input-number v-model="ruleform.chfsl" placeholder="请输入产后访视率" :controls="false" clearable min="0"
                max="100" precision="2" style="width: 100%;"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="save_validate()">保 存</el-button>
      <el-button @click="closeDialog">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
  import {
    save,
    info
  } from '@/api/zqgl/ycfsj';
  export default {
    name: 'Ycfsj_edit',

    components: {},
    props: {
      dialogedit: {
        type: Boolean,
        default: false
      },
      id: {
        type: String,
        default: '0'
      }
    },
    data() {
      return {
        title: '新增数据',
        ruleform: {
          id: 0,
          rq: '',
          cfcs: '',
          zycs: '',
          fscs: '',
          zyjcl: '',
          chfsl: '',
        },


        rules: {
          rq: [{
            required: true,
            message: '填报日期不能为空'
          }]
        },

      };
    },
    created() {

    },
    methods: {
      closeDialog() {
        this.$nextTick(() => {
          this.$refs.formdata.resetFields();
          this.$emit('update:dialogedit', !this.dialogedit);
        });
      },
      save_validate() {
        this.$refs.formdata.validate((valid, valids) => {
          if (valid) {
            this.saveData();
          } else {
            var msg = '';
            for (var key in valids) {
              var item = valids[key];
              msg = item[0].message;
              break;
            }
            if (msg) this.$message.error(msg);
            return false;
          }
        });
      },

      async saveData() {
        const loading = this.loading('保存中...');
        var params = {}
        params = this.ObjParams(this.ruleform, params);
        save(params).then(response => {
          this.$modal.msgSuccess("保存成功");
          loading.close();
          this.closeDialog();
          this.$emit('reload');
        }).catch(err => {
          loading.close();
        });
      },
      get_info() {
        var Parmas = {
          id: this.id
        }
        info(Parmas).then(res => {
          this.ruleform = {
            id: res.data.id,
            rq: res.data.rq,
            cfcs: res.data.cfcs,
            zycs: res.data.zycs,
            fscs: res.data.fscs,
            zyjcl: res.data.zyjcl,
            chfsl: res.data.chfsl
          }

        });
      },
      async openDialog() {
        if (this.id == '0') {
          this.ruleform = {
            id: 0,
            rq: '',
            cfcs: '',
            zycs: '',
            fscs: '',
            zyjcl: '',
            chfsl: '',
          }
          this.title = "新增数据";
        } else {
          this.get_info();
          this.title = "修改数据";
        }

      }
    }
  };
</script>

<style scoped>
  .form-box {
    min-height: 250px;
    padding-right: 10px;
    overflow: auto;
  }
</style>
